package com.naxian.service.Impl;

import com.github.pagehelper.PageInfo;
import com.naxian.mapper.CompanyMapper;
import com.naxian.mapper.RecruitMapper;
import com.naxian.pojo.Company;
import com.naxian.pojo.CompanyExample;

import com.naxian.pojo.Recruit;
import com.naxian.pojo.RecruitExample;
import com.naxian.service.company.CompanyService;
import com.naxian.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/10/7.
 */
@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private RecruitMapper recruitMapper;
    @Override
    public boolean save(Company company) {
        return false;
    }

    @Override
    public boolean update(Company company) {
        return false;
    }

    @Override
    public Company getById(int companyId) {
        Company company = companyMapper.selectByPrimaryKey(companyId);

        System.out.println("company信息:"+company);
        return company;
    }

    @Override
    public JsonResult getByTelno(Long companyTelno) {
        return null;
    }


    @Override
    public PageInfo<Company> findByPage(Integer pageNum) {
        return null;
    }
//根据公司名和密码登录
    @Override
    public JsonResult loginByPerNameAndPwd(String companyName, Integer pwd) {
        System.out.println("companyName:"+companyName);
        System.out.println("pwd:"+pwd);
        Company company = null;
        CompanyExample companyExample =new CompanyExample();
        CompanyExample.Criteria companyCriteria = companyExample.createCriteria();
        companyCriteria.andCompanyNameEqualTo(companyName);
        companyCriteria.andPwdEqualTo(pwd);

        List<Company> companyList =companyMapper.selectByExample(companyExample);
        if (companyList.size()!=0){
            company = companyList.get(0);
            return new JsonResult(1,"查询到该用户，可以登陆",company);
        }else {
            return new JsonResult(0,"没有查询到该用户，请前往注册",company);
        }

    }

    @Override
    public List<Company> getAllCompany() {
       return  companyMapper.selectByExample(null);
    }

    @Override
    public int  recruitIn(Recruit recruit) {
        int rows = recruitMapper.insert(recruit);

//        int recId = recruit.getRecId();
        return rows;

    }

    @Override
    public Recruit getByRecId() {
        List<Recruit> recruitList = recruitMapper.selectByExample(null);
        Recruit recruit= recruitList.get(recruitList.size()-1);
//        Recruit recruit = recruitMapper.selectByPrimaryKey(recId);

        return recruit;
    }

    @Override
    public Company login(String username, Integer pwd) {
        CompanyExample companyExample = new CompanyExample();
        CompanyExample.Criteria criteria = companyExample.createCriteria();
        criteria.andCompanyNameEqualTo(username);
        criteria.andPwdEqualTo(pwd);
        List<Company> companyList = companyMapper.selectByExample(companyExample);
        Company company = companyList.get(0);
        if(company!=null){
            return company;
        }
        return  null;
    }


}